Preparations

Load the necessary libraries

library(mgcv)      #for GAMs
library(gratia)    #for GAM plots
library(emmeans)   #for marginal means etc
library(broom)     #for tidy output
library(MuMIn)     #for model selection and AICc
library(lubridate) #for processing dates
library(tidyverse) #for data wrangling
library(DHARMa)    #for residuals diagnostics
library(performance) #for residual disagnostics
library(see)        # to visualize residual diagnostics
library(patchwork)  #for grids of plots

Scenario

The Australian Institute of Marine Science (AIMS) have a long-term inshore marine water quality monitoring program in which water samples are collected and analysed from sites (reef.alias) across the GBR numerous times per year. The focus of this program is to report long-term condition and change in water quality parameters.

Although we do have latitude and longitudes, the nature of the spatial design predominantly reflects a series of transects that start near the mouth of a major river and extend northwards, yet mainly within the open coastal zone. As a result, this design is not well suited to any specific spatial analyses (since they are mainly one dimensional).

AIMS water quality monitoring

Format of aims.wq.csv data file

LATITUDE LONGITUDE reef.alias Water_Samples Region Subregion Season waterYear NOx
-16.1 145. Cape Trib… AIMS Wet T… Barron D… Dry 2008 0.830
-16.1 145. Cape Trib… AIMS Wet T… Barron D… Wet 2008 0.100
-16.1 145. Cape Trib… AIMS Wet T… Barron D… Dry 2009 0.282
-16.1 145. Cape Trib… AIMS Wet T… Barron D… Wet 2009 1.27
-16.1 145. Cape Trib… AIMS Wet T… Barron D… Dry 2009 0.793
-16.1 145. Cape Trib… AIMS Wet T… Barron D… Dry 2010 0.380
... ... ... ... ... ... ... ... ...
LATITUDE - Latitudinal coordinate
LONGITUDE - Longitudinal coordinate
reef.alias - Internal AIMS reef name
Water_Samples - Categorical label of who collected the data
Region - The MMP region
Subregion - The MMP subregion
Season - A categorical listing of Wet or Dry
waterYear - The water year (1st Oct - 30 Sept) to which the data are attached
Date - The date the sample was collected
NOx - Nitrite and Nitrate

Read in the data

wq = read_csv('../public/data/aims.wq.csv', trim_ws=TRUE)
glimpse(wq)
## Rows: 618
## Columns: 57
## $ LATITUDE         <dbl> -16.11152, -16.11383, -16.11261, -16.11308, -16.11343…
## $ LONGITUDE        <dbl> 145.4833, 145.4827, 145.4844, 145.4868, 145.4835, 145…
## $ reef.alias       <chr> "Cape Tribulation", "Cape Tribulation", "Cape Tribula…
## $ Water_Samples    <chr> "AIMS", "AIMS", "AIMS", "AIMS", "AIMS", "AIMS", "AIMS…
## $ Region           <chr> "Wet Tropics", "Wet Tropics", "Wet Tropics", "Wet Tro…
## $ Subregion        <chr> "Barron Daintree", "Barron Daintree", "Barron Daintre…
## $ Season           <chr> "Dry", "Wet", "Dry", "Wet", "Dry", "Dry", "Wet", "Dry…
## $ waterYear        <dbl> 2008, 2008, 2009, 2009, 2009, 2010, 2010, 2010, 2011,…
## $ Date             <date> 2007-10-14, 2008-03-30, 2008-10-12, 2009-02-26, 2009…
## $ Mnth             <dbl> 10, 3, 10, 2, 6, 10, 3, 6, 10, 2, 6, 10, 2, 6, 10, 2,…
## $ Dt.num...11      <dbl> 2007.784, 2008.243, 2008.779, 2009.153, 2009.452, 200…
## $ Source           <chr> "AIMS Niskin", "AIMS Niskin", "AIMS Niskin", "AIMS Ni…
## $ CDOM_443         <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ CHL_TSS          <dbl> 0.3101798, 0.1077403, 0.1927524, 0.4841206, 0.2699770…
## $ DIN              <dbl> NA, 1.7603107, 1.8912551, 1.5700109, 0.9340067, 0.853…
## $ DIP              <dbl> 3.2430236, 0.0000000, 8.4301889, 0.2818657, 3.3818466…
## $ DOC_DON          <dbl> 9.894332, 18.838502, 10.247938, 8.853276, 35.173595, …
## $ DOC_DOP          <dbl> 249.57930, 164.16894, 232.26052, 138.28572, 143.74990…
## $ DOC              <dbl> 568.7456, 800.0811, 665.5129, 790.8947, 709.3114, 703…
## $ DON_DOP          <dbl> 25.371405, 8.672342, 21.385520, 15.773521, 4.218696, …
## $ DON              <dbl> 58.39177, 42.59066, 66.56530, 89.86323, 21.04308, 65.…
## $ DOP              <dbl> 2.360146, 5.676724, -3.369768, 6.108445, 5.245931, 2.…
## $ DRIFTCHL_UGPERL  <dbl> 0.2348550, 0.3407700, 0.3229300, 0.3026219, 0.3904875…
## $ DRIFTPHAE_UGPERL <dbl> 0.10667250, 0.23786250, 0.14444250, 0.11588125, 0.186…
## $ Dt.num...25      <dbl> 2007.784, 2008.243, 2008.779, 2009.153, 2009.452, 200…
## $ Dtt.num          <dbl> 1192330200, 1206843900, 1223763420, 1235609580, 12450…
## $ HAND_NH4         <dbl> NA, 1.6579284, 1.1876348, 0.2446500, 0.1862600, 0.401…
## $ NH4              <dbl> 3.321632, 1.013287, 2.984873, 5.136503, 3.343649, 2.2…
## $ NO2              <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.1400100…
## $ NO3              <dbl> 0.8225237, 0.0000000, 0.2744196, 1.2644041, 0.6533917…
## $ NOx_PO4          <dbl> 0.233605384, Inf, 0.166195654, Inf, 0.207299638, 0.13…
## $ NOx              <dbl> 0.8300237, 0.0100000, 0.2819196, 1.2675291, 0.7934017…
## $ PN_CHL           <dbl> 50.81076, 70.97502, 43.20272, 32.14920, 40.25010, 31.…
## $ PN_PP            <dbl> 5.457474, 4.841050, 5.852297, 5.035881, 5.801272, 4.0…
## $ PN_SHIM          <dbl> 18.99411, 29.22387, 13.21873, 14.93224, 18.73589, 14.…
## $ PN_TSS           <dbl> 0.017091541, 0.007517002, 0.008352101, 0.014976245, 0…
## $ PN               <dbl> 9.556838, 17.876092, 13.877616, 9.648177, 13.335427, …
## $ PO4              <dbl> 3.2430236, 0.0000000, 8.4301889, 0.2818657, 3.3818466…
## $ POC_CHL          <dbl> 643.2646, 594.1710, 320.9770, 300.8186, 334.7438, 274…
## $ POC_PN           <dbl> 13.802976, 8.211349, 7.611680, 9.477119, 8.455543, 8.…
## $ POC_PP           <dbl> 78.17430, 39.91906, 43.86293, 46.88621, 48.09479, 34.…
## $ POC_TSS          <dbl> 0.28442285, 0.06276370, 0.06193767, 0.14314580, 0.093…
## $ POC              <dbl> 126.47385, 147.34368, 103.58926, 89.97550, 110.71416,…
## $ PP_CHL           <dbl> 9.073836, 13.775650, 7.352966, 6.429233, 6.769279, 7.…
## $ PP_TSS           <dbl> 0.002787327, 0.001460411, 0.001423642, 0.003094262, 0…
## $ PP               <dbl> 2.025051, 3.678694, 2.371837, 1.922521, 2.336996, 2.5…
## $ Salinity         <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ SECCHI_DEPTH     <dbl> 11.0, 4.0, 3.8, 6.0, 6.0, 11.0, 7.0, 3.5, 5.5, 6.5, 6…
## $ SI_NOx           <dbl> 5345.75834, 32763.52291, 8925.66237, 5725.21940, 391.…
## $ SI_PO4           <dbl> 20.99143, Inf, 42.09525, Inf, 59.47313, 10.50605, 59.…
## $ SI               <dbl> 70.47872, 327.63523, 119.92590, 196.88465, 160.96946,…
## $ TDN              <dbl> 62.53592, 43.60394, 69.82460, 96.26414, 25.18013, 68.…
## $ TDP              <dbl> 5.603170, 5.676724, 5.060421, 6.390311, 8.627777, 5.3…
## $ TN_TP            <dbl> 9.567956, 6.958258, 11.240651, 13.392960, 3.586795, 1…
## $ TotalN           <dbl> 72.09276, 61.48004, 83.70221, 105.91231, 38.51556, 78…
## $ TotalP           <dbl> 7.628221, 9.355418, 7.432258, 8.312832, 10.964774, 7.…
## $ TSS_MGPERL       <dbl> 1.052500, 3.120000, 1.695000, 0.761250, 1.505000, 1.4…

Exploratory data analysis

Model formula: \[ y_i \sim{} \mathcal{N}(\mu_i, \sigma^2)\\ \mu_i =\beta_0 + f(Date_i) + f(Month_i) \]

where \(\beta_0\) is the y-intercept. \(f(Date)\) and \(f(Month)\) indicate the additive smoothing functions of the long-term temporal trends and the annual seasonal trends respectively.

Data preparations

Simple model (Pandora only)

Exploring more models

Mixed model (all reefs)

Model investigation / hypothesis testing

Further analyses

Summary figures

References